package com.oa.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.oa.bean.WorkPlan;
import com.oa.dao.WorkPlanDao;
import com.oa.service.WorkPlanService;

@Service
public class WorkPlanServiceImpl implements WorkPlanService {

	@Resource
	WorkPlanDao workPlanDao;
	
	
	@Override
	public Integer addWorkPlan(WorkPlan plan) {
		// TODO Auto-generated method stub
		Integer result = workPlanDao.insertPlanJobByWorkPlan(plan);
		return result;
	}


	@Override
	public Map<String, Object> getWorkPlanList(String tiele,String endDate,String startDate,Integer currentPage,Integer uid) {
		// TODO Auto-generated method stub
		Map<String,Object> map = new HashMap<>();
		Page page = PageHelper.startPage(currentPage, 2,"pid desc");
		map.put("title", tiele);
		map.put("endDate", endDate);
		map.put("startDate", startDate);
		map.put("uid", uid);
		List<WorkPlan> list = workPlanDao.selectWorkPlan(map);
		Map<String,Object> result = new HashMap<>();
		result.put("planList", list);
		result.put("mixPages", page.getPages());
		result.put("limit", 2);
		return result;
	}


	@Override
	public String updateWorkPlan(Integer pid) {
		// TODO Auto-generated method stub
		Integer result = workPlanDao.updateStateById(pid);
		if(result!=0){
			return "true";
		}
		return "false";
	}


	@Override
	public WorkPlan getPlanOne(Integer pid) {
		// TODO Auto-generated method stub
		WorkPlan plan = workPlanDao.selectPlanById(pid);
		return plan;
	}


	@Override
	public String changeWorkPlan(WorkPlan plan) {
		// TODO Auto-generated method stub
		Integer result = workPlanDao.updateWorkPlan(plan);
		if(result!=0){
			return "true";
		}
		return "false";
	}


	@Override
	public String deleteWorkPlanArray(int[] array) {
		// TODO Auto-generated method stub
		Integer result = workPlanDao.delectPlanByArray(array);
		if(result!=0){
			return "true";
		}
		return "false";
	}


	@Override
	public Map<String, Object> getMyJoinPlan(String name,Integer currentPage) {
		// TODO Auto-generated method stub
		Page page = PageHelper.startPage(currentPage, 2);
		List<WorkPlan> list = workPlanDao.selectJoinPlan(name);
		Map<String,Object> map = new HashMap<>();
		map.put("planList", list);
		map.put("mixPages", page.getPages());
		map.put("limit", 2);
		return map;
	}

}
